// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import BaseClass from '@api/base/model/DeviceDto'
import state from '@admin/views/System/IOT/IOTList/store/state'

const WORD = '直梯'

// ============================== 导出状态集 ============================== //

export default {
  // —————————————————————————————— 常量状态 —————————————————————————————— //

  /**
   * 接口
   */
  API: {
    MENU: ['__详情__', WORD], // 菜单
    getOne: state.API.getOne,
    transOne(obj, { state: { DICT } }) {
      const property = obj.property || []
      obj.props = {}
      DICT.PROP_DICT.forEach(([code, , dict]) => {
        const matched = property.find((prop) => prop.propertyCode === code) || {}
        matched.value = matched.propertyValue || ''
        matched.text = dict ? CORE.dict(dict, matched.value) : matched.value
        obj.props[code] = matched
      })
      return obj
    },
  },

  /**
   * 映射
   */
  MAP: {
    // 词语
    WORD,

    // 必须的字段，有值才会显示弹窗
    REQUIRED_KEY: 'id',

    // 弹窗属性
    MODEL_PROPS: {
      title: `${WORD}详情`,
      small: true,
      bgClose: true,
      noFooter: true,
    },
  },

  /**
   * 字典
   */
  DICT: {
    /**
     * 属性字典
     */
    PROP_DICT: [
      ['status', '状态', [['0', '未知'], ['1', '不在线'], ['2', '在线']]],
      ['floor', '当前显示楼层'],
      ['runState', '行梯状态', [['0', '停止'], ['1', '上行'], ['2', '下行']]],
      ['level', '平层状态', [['0', '非平层'], ['1', '平层']]],
      ['door', '门开关状态', [['0', '开门'], ['1', '关门']]],
      ['speed', '当前速度'],
      ['openClose', '开关门次数'],
      ['stop', '停站次数'],
      ['runDis', '运行距离(cm)'],
      ['runTime', '运行时长(S)'],
      ['passengerStatus', '梯内是否有人', [['0', '无人'], ['1', '有人'], ['2', '未知']]],
      ['faultName', '故障名称'],
      ['playUrl', '直播地址'],
      ['sendTime', '更新时间'],
      ['faultCreateTime', '故障时间'],
      ['maintainFinishTime', '最近维保时间'],
    ],
  },

  /**
   * 首要开关
   *
   * 1. 初始化完成时调用
   * 2. 提交后刷新时调用
   */
  MAIN_START: 'startOne', // 'startInfo' 或 'startList' 或 'startOne' 或 ''

  /**
   * 初始单项
   *
   * 1. 初始存在，才能响应
   * 2. setOne() 合并时使用
   * 3. openAdd() 新增时使用
   */
  INIT_ONE: CORE.initObj(BaseClass, {
    props: {
      door: {},
      speed: {},
      level: {},
      floor: {},
      stop: {},
      faultName: {},
      runState: {},
      openClose: {},
      runDis: {},
      runTime: {},
      passengerStatus: {},
      sendTime: {},
      faultCreateTime: {},
      maintainFinishTime: {},
    },
  }),
}
